<!-- 管理员 登录日志 -->
<template>
    <el-scrollbar class="vue-box">
        <div class="c-card">
            <h4 class="c-title">管理员登录日志</h4>
            <!-- ------------- 查询条件 ------------- -->
            <el-form class="select-form" :inline="true" label-width="6em" @keyup.enter="state.p.pageNo = 1; f5();">
                <in-input type="num" name="记录id：" v-model="state.p.id"></in-input>
                <in-input type="num" name="管理员id：" v-model="state.p.accId"></in-input>
                <in-input type="text" name="登录令牌：" v-model="state.p.accToken"></in-input>
                <in-input type="text" name="登陆IP：" v-model="state.p.loginIp"></in-input>
                <in-item class="ok-item">
                    <el-button type="primary" icon="el-icon-Search" @click="state.p.pageNo = 1; f5();">查询</el-button>
                </in-item>
            </el-form>
            <!-- ------------- 操作按钮 ------------- -->
            <div class="fast-btn">
                <el-button type="primary" plain icon="el-icon-Download" @click="sa.exportExcel()">导出</el-button>
                <el-button type="danger" plain icon="el-icon-Delete" @click="deleteByIds">批量删除</el-button>
                <el-button type="default" plain icon="el-icon-Refresh" @click="sa.f5CurrView()">重置</el-button>
            </div>
            <!-- ------------- 数据表格 ------------- -->
            <el-table :data="state.dataList" class="data-table" ref="data-table" row-key="id">
                <td-info type="selection"></td-info>
                <td-info name="记录id" prop="id" width="90px"></td-info>
                <td-info name="登录账号" width="160px">
                    <template #default="s">
                        <img
                            :src="s.row.spAdminAvatar" @click="sa.showImage(s.row.spAdminAvatar, '400px', '400px')"
                            class="td-img" style="vertical-align: middle; margin-right: 5px;" alt="img" />
                        <el-link type="primary" @click="sa.showModel('管理员详情 - ' + s.row.accId, import('../sp-admin/admin-info'), { id: s.row.accId })">
                            <b style="font-weight: 400;">{{ s.row.spAdminName }}</b>
                        </el-link>
                    </template>
                </td-info>
                <td-info name="登陆IP" prop="loginIp"></td-info>
                <td-info name="客户端标识" prop="loginDevice"></td-info>
                <td-info name="所属系统" prop="loginSystem"></td-info>
                <td-info name="登录地" prop="loginAddress"></td-info>
                <td-info name="本次登录Token" prop="accToken" min-width="120px"></td-info>
                <td-info name="登录时间" width="220px">
                    <template #default="s">
                        <span>{{ sa.forDate(s.row.createTime, 2) }}</span> -
                        <b style="color: green;">{{ sa.isNull(sa.forDate2(s.row.createTime), '无') }}</b>
                    </template>
                </td-info>
                <el-table-column label="操作" fixed="right" width="120px">
                    <template #default="s">
                        <el-button class="c-btn" type="danger" plain icon="el-icon-Delete" @click="del(s.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- ------------- 分页按钮 ------------- -->
            <div class="page-box">
                <el-pagination
                    background layout="total, prev, pager, next, sizes, jumper"
                    v-model:current-page="state.p.pageNo" v-model:page-size="state.p.pageSize" :total="state.dataCount" 
                    :page-sizes="[1, 10, 20, 30, 40, 50, 100]"
                    @current-change="f5()" @size-change="f5()">
                </el-pagination>
            </div>
        </div>
    </el-scrollbar>
</template>

<script setup name="sp-admin-login">
import TdInfo from '../../sa-frame/com/td/td-info';
import {getCurrentInstance, onMounted, reactive} from "vue";
import InInput from "../../sa-frame/com/in/in-input";
import router from "../../router";
const { proxy } = getCurrentInstance();

// ------------------ 数据 ------------------
const state = reactive({
    p: {    // 查询条件 
        id: '',		// id号
        accId: router.currentRoute.value.meta.accId || '',		// 管理员id
        accToken: '',		// 本次登录Token
        loginIp: '',		// 登陆IP
        pageNo: 1,		// 当前页
        pageSize: 10,	// 页大小
        sortType: 0		// 排序方式
    },
    dataCount: 0,   // 数据总数 
    dataList: []   // 数据表格 
})

// 组件加载时执行函数
onMounted(function () {
    f5();
})

// ------------------ 函数 ------------------
// 查找数据
const f5 = function() {
    sa.ajax('/SpAdminLogin/getList', state.p, function(res) {
        state.dataList = res.data;	// 数据
        state.dataCount = res.dataCount;
    });
};

// 删除
const del = function(data) {
    sa.confirm('是否删除，此操作不可撤销', function(){
        sa.ajax('/SpAdminLogin/delete', { id: data.id }, function(res){
            sa.arrayDelete(state.dataList, data);
            sa.ok('删除成功');
        })
    });
};
// 批量删除
const deleteByIds = function() {
    // 获取选中元素的id列表
    let selection = proxy.$refs['data-table'].getSelectionRows();
    let ids = sa.getArrayField(selection, 'id');
    if(selection.length === 0) {
        return sa.msg('请至少选择一条数据');
    }
    // 提交删除
    sa.confirm(`是否删除选中的 ${selection.length} 条数据？此操作不可撤销`, function() {
        sa.ajax('/SpAdminLogin/deleteByIds', { ids: ids.join(',') }, function(res) {
            sa.arrayDelete(state.dataList, selection);
            sa.ok('删除成功');
        })
    });
};

// 对外开放函数 
defineExpose({f5})

</script>

<style scoped lang="scss">

</style>
